﻿package net;

import java.io.IOException;

/**
 * ESCHandler 处理转义字符，将转义字符替换成正确的显示结果
 * 
 * @author Lijie Wang, wanglj07@sei.pku.edu.cn 2010-12-12
 */
public class ESCHandler {
	private static String[][] ESCs = { 
		{"&nbsp;"," "}, 
		{"&emsp;"," "},
		{"&ensp;"," "},
		{"&lt;","<"},
		{"&gt;",">"},
		{"&amp;","&"},
		{"&quot;","\""}};
	/**
	 * 将将转义字符替换成正确的显示结果
	 * @param content 待转换的文本内容
	 * @return String 替换后的文本
	 */
	public static String replaceESC(String content){
		for(int i = 0;i<ESCs.length;i++){
			content = content.replaceAll(ESCs[i][0], ESCs[i][1]);
		}
		return content;
	}
	/**
	 * 将一些特殊字符 < > 替换成其转义字符
	 * @param content < > ...
	 * @return String &lt; &gt;...
	 */
	public static String convertESC(String content){
		for(int i = 3;i<5;i++){
			content = content.replaceAll(ESCs[i][1], ESCs[i][0]);
		}
		return content;
	}
	/**
	 * @param args
	 *            void
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
	}

}
